<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<script type="text/javascript">
$(function(){
    $("#searchTree",navTab.getCurrentPanel()).baseTreeSearch({
        inputTextId : "#searchWorkCenter", //搜索框的id
        alertMsg : "<@label key='treeSearchContent.D'>请输入内容再查找</@label>", //提示内容，要考虑国际化，传自后台
        $p : navTab.getCurrentPanel()
    });
    
    $("#collapsable",navTab.getCurrentPanel())._treeCollapsable({
        $p : navTab.getCurrentPanel()
    })
    
    $("#expandable",navTab.getCurrentPanel())._treeExpandable({
        $p : navTab.getCurrentPanel()
    })
    
});

function _addTopWorkCenter(_top) {
    var parentWorkCenterCode;
    if(_top && _top=='top'){
        parentWorkCenterCode = "";
    }else{
        var node = $("div#workCentertree", navTab.getCurrentPanel()    ).find("div.selected").parent("li");
        if(node && node.length == 1){
            var $a = _getChildren(node);
            parentWorkCenterCode =  $a.attr("code");
        }else{
            alertMsg.error("<@label key='Add_WorkCenter_Msg.D'>请选择一个工作中心操作!</@label>");
            return;
        }
    }
    $("div#workCenter_detail", navTab.getCurrentPanel()).loadUrl(hostUrl+"/workCenter/addWorkCenter", {parentWorkCenterCode:parentWorkCenterCode});
}

function _deleteWorkCenter(){
    var node = $("div#workCentertree", navTab.getCurrentPanel()    ).find("div.selected").parent("li");
    if(node && node.length == 1){
        var $a = _getChildren(node);
        var _code =  $a.attr("code");
        var isLeaf = $a.attr("isLeaf")
        if(isLeaf == "no"){
            alertMsg.error("<@label key='Tree_delete_msg.D'>非叶子节点不能删除!</@label>");
            return;
        }
        alertMsg.confirm("<@label key='delete_sure.D'>确定删除</@label>【"+$a.attr("name")+"】？",{
            okCall:function(){
                $.DWZajax({
                    url:hostUrl +"/workCenter/deleteWorkCenter",
                    data:{'workCenterCode':_code},
                    callback:function(data){
                        alertMsg.correct("<@label key='Tree_deleteS_msg.D'>成功删除</@label>【"+$a.attr("name")+"】");
                        navTab.reload(hostUrl + "/workCenter/workCenterTree?navTabId=${navTabId!''}");
                    }
                });
            }
        });
    }else{
        alertMsg.error("<@label key='Add_WorkCenter_Msg.D'>请选择一个工作中心操作!</@label>");
        return;
    }
}

function viewWorkCenter(_code, siteCode){
    if(_code){
        $("div#workCenter_detail", navTab.getCurrentPanel()).loadUrl(hostUrl+"/workCenter/viewWorkCenter", {workCenterCode:_code,siteCode:siteCode, navTabId:'${navTabId!''}'});
    }
}

function _getChildren($obj) {
    return $obj.children("div").children("a");
}
</script>

<div class="pageContent">
    <div>
        <div id="workCentertree" class="treeleft">
            <div class="mini-toolbar">
                <input type="text" id="searchWorkCenter" /> <a class="buttonActive" href="javascript:void(0)" id="searchTree"><span><@label key='search.B'>搜索</@label></span>
                </a>
            </div>
            <div class="pBar pBarBorder">
                <ul class="toolBar">
                    <@buttonRight menuCode="workCode_add" labelKey="add.B,topTree.C,workCenter.C" defalutName="新增顶级工作中心">
                    <li><a class="add" onclick="_addTopWorkCenter('top');" title="<@label key='add.B,topTree.C,workCenter.C'>新增顶级工作中心</@label>"><span><@label key="add.B,topTree.C,workCenter.C">新增顶级工作中心</@label></span>
                    </a>
                    </li></@buttonRight> <@buttonRight menuCode="workCode_add" labelKey="add.B,workCenter.C" defalutName="新增工作中心">
                    <li><a class="add" onclick="_addTopWorkCenter();" title="<@label key='add.B,workCenter.C'>新增工作中心</@label>"><span><@label key="add.B,workCenter.C">新增工作中心</@label></span>
                    </a>
                    </li></@buttonRight> 
                </ul>
            </div>
            <div id="menuBar" class="pBar pBarBorder">
                <ul class="toolBar">
                <@buttonRight menuCode="workCode_delete" labelKey="delete.B,workCenter.C" defalutName="删除工作中心">
                    <li><a class="delete" onclick="_deleteWorkCenter();" title="<@label key='delete.B,workCenter.C'>删除工作中心</@label>"><span><@label key="delete.B,workCenter.C">删除工作中心</@label></span>
                    </a>
                    </li></@buttonRight>
                    <li><a class="collapse" id="collapsable" title="<@label key="collapseAll.D">全部收起</@label>"><span><@label key="collapse.B">收起</@label></span> </a></li>
                    <li><a class="expand" id="expandable" title="<@label key="expandAll.D">全部展开</@label>"><span><@label key="expand.B">展开</@label></span> </a></li>
                </ul>
            </div>
            <div layoutH="95">
                <ul class="tree treeFolder expand">
                    <#if workCenterTree??> <#list workCenterTree as workCenter>
                    <li><a code="${workCenter.workCenterCode!''}" parentCode="${workCenter.parentWorkCenterCode!''}" isLeaf="${workCenter.isLeaf?string('yes','no')}" name="${workCenter.workCenterText!''}" onclick="viewWorkCenter('${workCenter.workCenterCode!''}', '${workCenter.siteCode!''}')">${workCenter.workCenterText!''}</a> <#if workCenter.childrens??>
                        <ul><@macroWorkCenterTree children=workCenter.childrens />
                        </ul> </#if></li> </#list> </#if>
                </ul>
            </div>
        </div>
        <div id="workCenter_detail" layoutH="10" class="unitBox treeBox" >
                        <div class="treeTip"><@label key="treeTips.M">请点击左侧树形菜单进行相关操作</@label></div>
        </div>

    </div>
</div>
<!-- 递归产生树的宏定义 -->
<#macro macroWorkCenterTree children> <#if children?? && children?size gt 0> <#list children as workCenter>
<li><a code="${workCenter.workCenterCode!''}" isLeaf="${workCenter.isLeaf?string('yes','no')}" name="${workCenter.workCenterText!''}" parentCode="${workCenter.parentWorkCenterCode!''}" onclick="viewWorkCenter('${workCenter.workCenterCode!''}', '${workCenter.siteCode!''}')">${workCenter.workCenterText!''}</a> <#if workCenter.childrens??>
    <ul><@macroWorkCenterTree children=workCenter.childrens />
    </ul> </#if></li>
</#list> </#if> </#macro>
